/*
 * @Descripttion: 
 * @version: 1
 * @Author: Saiu
 * @Date: 2019-10-28 21:57:32
 * @LastEditors: 
 * @LastEditTime: 2019-10-29 23:29:23
 */
import axios from 'axios';
import configts from '/config.js';
const service = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境
    baseURL: configts.apiUrl+'api/v1/',
    //baseURL: 'https://localhost:5001/api/v1/',
    //baseURL: 'http://101.132.175.178:81/v1/',
    timeout: 500000,
    headers: {
        // 'Content-Type': 'application/x-www-form-urlencoded',
        'Content-Type': 'application/json',
    }
})

// service.interceptors.request.use(config => {
//     // 判断请求是否是登陆
//     if (config.url != "oauth/admintoken") {
//         config.headers = {
//             // 'Content-Type': 'application/x-www-form-urlencoded',
//             'Content-Type': 'application/json',
//             'Authorization': 'Bearer ' + localStorage.getItem("tokenStr")
//         }
//     }

//     var result = "";
//     if (config.data != null) {
//         for (var p in config.data) { //遍历json对象的每个key/value对,p为key

//             result += p + "=" + config.data[p] + "&";

//         }

//         result = result.substr(0, result.length - 1);
//     }


//     config.data = result;

//     return config;
// }, error => {
//     console.log(error);
//     return Promise.reject();
// })

service.interceptors.response.use(response => {
    if (response.status === 200) {
        return response.data;
    } else {
        Promise.reject();
    }
}, error => {
    console.log(error);
    return Promise.reject();
})

export default service;